package com.zf.shuashua.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;

import com.zf.shuashua.manager.LoginRecordManager;

public class NetWorkStateReceiver extends BroadcastReceiver {
    private String lastTypeName = "";
    @Override
    public void onReceive(Context context, Intent intent) {
        if(context == null){
            return;
        }
        ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()){
            String currentName = networkInfo.getTypeName();
            if(!TextUtils.isEmpty(currentName)){
                if(!currentName.equals(lastTypeName)){
                    LoginRecordManager.getInstance().loginRecord();
                    lastTypeName = currentName;
                }
            }
        }
    }
}
